<?php
class message extends control
{
	/* 构造函数。*/
	public function __construct()
	{
		parent::__construct('');
	}

	public function index_o(){
		//$this->assign();
		$this->assign('incjs', array('index','message'));

		if(empty($_POST)){

		}else{
			echo $_POST['msg_author'];
		}
		$this->display();
	}
	public function index($recTotal=0, $recPerPage=10, $pageID=1){
		
		$doneflag='';
		if(!empty($_POST)){
			
			$setarr=array();
			$fields=array('msg_author','msg_company','msg_tel','msg_email','msg_title','msg_content');
			foreach ($_POST as $k=>$v){
				if(in_array($k, $fields)){
					$setarr[$k]= str_replace('>','&gt;',str_replace('<','&lt;',$v));
					
				}
			}			
			$setarr['msg_addtime']=date("Y-m-d H:i:s");
			$data=$this->message->add($setarr);
			
			$doneflag='添加成功，感谢留言～';

		}
		$this->app->loadClass('pager');
		$pager = new pager($recTotal, $recPerPage, $pageID);
		$data = $this->message->findByPage($pager);
		
		$this->assign('doneflag', $doneflag);
		$this->assign('incjs', array('index','message'));
		$this->assign('data', $data);
		$this->assign('pager', $pager->get('right'));
		$this->display();
	}

	public function add(){
		//var_dump($_POST);
		header("Location:".$this->createLink("message", "index"));
	}
	public function chkyzm($yzm){
		$yzm = isset($yzm) ? trim($yzm) : '';
		if(empty($yzm)) die('0');
		if($_SESSION['VAL_CODE'] == $yzm){
			echo '1';
		}else{
			echo '0';
		}
	}

}
